package com.dorm.mapper;

import com.dorm.entity.Student;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface StudentMapper {
    @Select("SELECT * FROM students")
    List<Student> findAll();

    @Select("SELECT * FROM students WHERE id = #{id}")
    Student findById(Long id);

    @Select("SELECT * FROM students WHERE room_id = #{roomId}")
    List<Student> findByRoomId(Long roomId);

    @Insert("INSERT INTO students(student_number, name, gender, phone, room_id) " +
            "VALUES(#{studentNumber}, #{name}, #{gender}, #{phone}, #{roomId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Student student);

    @Update("UPDATE students SET student_number = #{studentNumber}, " +
            "name = #{name}, gender = #{gender}, phone = #{phone}, " +
            "room_id = #{roomId} WHERE id = #{id}")
    int update(Student student);

    @Delete("DELETE FROM students WHERE id = #{id}")
    int deleteById(Long id);

    // 这个方法的具体实现在XML中定义
    Student findStudentWithDetails(Long id);
} 